# -*- coding: utf-8 -*-

"""
This script can generate keyword_mel.py and keyword_py.py from Maya Manual.
These files are used for syntax highlight function.
"""

melHelpFile = 'C:\\Program Files\\Autodesk\\Maya2008\\docs\\Maya2008\\en_US\\Commands\\index_all.html'
melKeywordsFile = 'keyword_mel.py'
pyHelpFile = 'C:\\Program Files\\Autodesk\\Maya2008\\docs\\Maya2008\\en_US\\CommandsPython\\index_all.html'
pyKeywordsFile = 'keyword_py.py'


def generateKeywordFile(source, resFile):
	o = open(resFile, 'w')
	o.write('kwlist = [\n')
	f = open(source,'r')
	for  line in f:
		if line.startswith('<a href'):
			word = line.split('"')[1].split('.')[0]
			o.write('\t"' + word + '",\n')
	f.close()
	o.write('\t]')
	o.close()


generateKeywordFile(melHelpFile, melKeywordsFile)
generateKeywordFile(pyHelpFile, pyKeywordsFile)
